<template>
  <div id="home">
    <!-- 页面主体区域 -->
    <el-container class="home-container">
      <!-- 页面头部区域 -->
      <el-header>
        <div class="header-left">
          <img src="../assets/logo.png" alt />
          <span>电商后台管理系统</span>
        </div>
        <el-button type="info" @click="quit">退出</el-button>
      </el-header>
      <el-container>
        <!-- 页面左侧区域 -->
        <el-aside :width="asidepx">
            <div class="toggle" @click="menuCollapse">
|||
            </div>
          <el-menu :default-active="'/'+activePath" router background-color="#333744" text-color="#fff" active-text-color="#409eff" :unique-opened="true" :collapse="flag" :collapse-transition="false">
            <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
                <!-- 一级菜单模板区域 -->
              <template slot="title">
                <i :class="iconsObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>

              <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                  <!-- 二级菜单模板区域 -->
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 页面main区域 -->
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  name: "home",
 data () {
     return {
       flag:false,
       asidepx:'200px',
       activePath:'',
menulist:[],
iconsObj:{
    '125':'iconfont icon-user',
    '103':'iconfont icon-tijikongjian',
    '101':'iconfont icon-shangpin',
    '102':'iconfont icon-danju',
    '145':'iconfont icon-baobiao'

}
     }
 },
  methods: {
    quit() {
      sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
    menuCollapse() {
     this.flag = !this.flag
     if(this.flag){
       this.asidepx = '64px'
     }else {
        this.asidepx = '200px'
     }
    },
    saveNavState(activePath) {
      // this.$router.push('/'+path)
      sessionStorage.setItem('activePath',activePath)
      this.activePath = activePath
    },
   async getMenuList() {
       const {data:res}  =  await this.$http.get('menus')
       if(res.meta.status!==200) return this.$message.error(res.meta.msg)
      this.menulist =  res.data
       console.log(res);

       
    }
  },
  created() {
     this.getMenuList()
     this.activePath = sessionStorage.getItem('activePath')
  },
};
</script>

<style lang="scss" scoped>
#home {
  height: 100%;
}
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  .header-left {
    display: flex;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
    }
    > span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
 
  .el-menu {
      border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.iconfont {
    margin-right: 10px;
}
 .toggle {
      background-color: #4a5064;
      font-size: 10px;
      height: 24px;
      line-height: 24px;
      text-align: center;
      color: #fff;
      letter-spacing: 0.2em;
  }
 


</style>
